package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteAppUserService;
import com.ruoyi.system.api.model.request.AppUserBalanceBatchOpetRequest;
import com.ruoyi.system.api.model.request.AppUserBalanceOpetRequest;
import com.ruoyi.system.api.model.user.AppUser;
import com.ruoyi.system.api.model.user.AppUserChum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Set;


@Component
public class RemoteAppUserFallbackFactory implements FallbackFactory<RemoteAppUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteAppUserFallbackFactory.class);

    @Override
    public RemoteAppUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteAppUserService() {
            @Override
            public R<AppUser> getUserInfo(Long userId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Set<Long>> getUserAttention(Long userId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> getUserIsAttention(Long userId, Long aimUserId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<AppUserChum> getUserChumInfo(Long id, String source) {
                return R.fail("获取用户密友关系失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> setAttention(Long userId, Long aimUserId, Long intimacyNum, String source) {
                return R.fail("设置互关失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> docBalance(AppUserBalanceOpetRequest request, String source) {
                return R.fail("扣减余额失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> aocBalance(AppUserBalanceOpetRequest request, String source) {
                return R.fail("增加余额失败:" + throwable.getMessage());
            }

            @Override
            public void aocBalanceByBatch(AppUserBalanceBatchOpetRequest request, String source) {

            }

            @Override
            public R<Boolean> setChum(Long id, Long aimUserId, String source) {
                return R.fail("设置密友关系失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> isMyFens(Long userId, Long aimUserId, String source) {
                return R.fail("获取是否粉丝失败:" + throwable.getMessage());
            }

            @Override
            public R<Set<Long>> getNewUser(String source) {
                return R.fail("获取新人用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Set<Long>> getCityWide(Long userId, String source) {
                return R.fail("获取同城数据失败:" + throwable.getMessage());
            }

        };
    }
}
